import pygame
import barlines
import math
import bullet

class Rest(object):
    def __init__(self,y_position,bar):
        super(Rest,self).__init__()
        self.img = pygame.image.load("../media/images/temp_rest.png").convert_alpha()
        self.rect = self.img.get_rect()
        self._vconst = -5
        self.velocity = -5
        self.rect.centerx = 1250
        self.rect.centery = y_position
        self.bar = bar
        self.locY = y_position
    def update(self,time):
        self.velocity = self._vconst * time
        self.rect.centery = math.fabs(self.bar.curveLoc(self.rect.x)+self.locY-(self.bar.locY))
        self.rect.move_ip(self.velocity,0)
    def draw(self,screen):
        screen.blit(self.img,self.rect)
    def collided(self,bullet_list = []):
        if self.rect.left <= 250:
            return 1
        elif len(bullet_list) > 0:
            for _bullet in bullet_list:
                if self.rect.colliderect(_bullet.rect):
                    bullet_list.remove(_bullet)
                    del _bullet
                    return 2
        else:
            return 0